#include "GsMusicPlayer.h"
#include "GsMusicPlayerImpl.h"

#define CHECK_RET(cod, ret) \
	if(!(cod)) return ret;

#define GSSAFE_DEL(ptr) \
	do{	\
	if(ptr) { delete ptr; ptr = NULL; }	\
	}while(0);


GsMusicPlayer::GsMusicPlayer() : 
m_pImpl(NULL)
{

}

GsMusicPlayer::~GsMusicPlayer()
{
	DeInit();
	GSSAFE_DEL(m_pImpl);
}

int GsMusicPlayer::Init( PlayStateEvent pStateEvent, void* pUserData/* = NULL*/ )
{
	CHECK_RET(!m_pImpl, -1);
	m_pImpl = new GsMusicPlayerImpl;
	CHECK_RET(m_pImpl, -1);
	return m_pImpl->Init_Impl(pStateEvent, pUserData);
}

int GsMusicPlayer::DeInit()
{
	CHECK_RET(m_pImpl, -1);
	return m_pImpl->DeInit_Impl();
}

int GsMusicPlayer::Play( const std::string& strFilePath, const std::string& strUrl /*= ""*/ )
{
	if (!m_pImpl)
	{
		Init(NULL);
	}
	CHECK_RET(m_pImpl, -1);
	return m_pImpl->Play_Impl(strFilePath, strUrl);
}

int GsMusicPlayer::Stop()
{
	CHECK_RET(m_pImpl, -1);
	return m_pImpl->Stop_Impl();
}

int GsMusicPlayer::Pause()
{
	CHECK_RET(m_pImpl, -1);
	return m_pImpl->Pause_Impl();
}

int GsMusicPlayer::Resum()
{
	CHECK_RET(m_pImpl, -1);
	return m_pImpl->Resum_Impl();
}

int GsMusicPlayer::SetVol( int nVol )
{
	CHECK_RET(m_pImpl, -1);
	return m_pImpl->SetVol_Impl(nVol);
}

int GsMusicPlayer::GetPlayState()
{
	if (!m_pImpl)
	{
		return ePlayUnKown;
	}
	return m_pImpl->GetPlayState_Impl();
}
